﻿<?php


function drawCommentsTable($newsId)
{
  $query = sprintf("SELECT comment.text, comment.date, comment.id, user.name
                    FROM users user, comments comment
                    WHERE (comment.news_id = %d AND comment.author_id = user.id) ORDER BY comment.date",
                    $newsId);
  $comments = mysql_query($query);
  if (!$comments)
  {
    //die('Беда=( ' .mysql_error());
  }
  $rownum = mysql_num_rows($comments);
  
  echo "<table width = \"100%\">";
 
  for ($i = 0; $i < $rownum; $i++) 
  {
      echo "<tr bgcolor=\"#FFFFCC\"><th colspan = \"2\">";
      echo "<table width = \"100%\" bordercolor = \"black\">";
      echo "<tr bgcolor=\"#FFFFCC\"><td></td><td></td><td></td></tr>";
      echo "<tr bgcolor=\"#FFFFCC\"><th colspan = \"3\" align = \"left\">";
      echo mysql_result($comments, $i, 'text');
      echo "</th></tr>";
      echo "<tr bgcolor=\"#FFFFCC\"><td align = \"left\">";
      echo mysql_result($comments, $i, 'name');
      echo "</td><td>&nbsp</td><td align = \"right\">";
      echo mysql_result($comments, $i, 'date');
      echo "</td></tr></table></th></tr>";      

	  if ($_SESSION['isAdmin'])
      {	
		$iId = mysql_result($comments, $i, 'id');
		echo "<tr>";
      	echo "<td bgcolor = \"white\">";
		echo "<form id=\"form";
		echo mysql_result($comments, $i, 'id');
		echo "\" action=\"delete_comment.php\" method=\"post\">";
        echo "<input name=\"id_deleted\" form=\"form";
		echo mysql_result($comments, $i, 'id');
		echo "\" value=\"";
		echo mysql_result($comments, $i, 'id');
		echo "\" type=\"hidden\"/>";
		
		 echo "<input name=\"id_rec\" form=\"form";
		echo mysql_result($comments, $i, 'id');
		echo "\" value=\"";
		echo  $newsId;
		echo "\" type=\"hidden\"/>";

        echo "<input type=\"submit\" value=\"Удалить\" />";
		echo "</form>";
        echo "</td></tr>";
      }	  
  }
  echo "</table>";
}


?>

